package com.kasax.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.kasax.lifecycle.BaseActLifecycleObserver

open abstract class BasicBindingActivity<V : ViewDataBinding> : AppCompatActivity() {
    var viewBinding: V? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (getLayoutId() == 0) {
            throw RuntimeException("getLayoutId() must be implemented")
        }

        viewBinding = DataBindingUtil.setContentView(this, getLayoutId())

        lifecycle.addObserver(BaseActLifecycleObserver(this))

        initView()
        addListeners()
        initData()
    }

    open fun initData() {
    }

    open fun addListeners() {
    }

    open fun initView() {
    }

    abstract fun getLayoutId(): Int
}